#!/bin/bash

# 检查grub配置是否包含密码设置
grub_config_ok=false
if grep -E "password_pbkdf2|set superusers" /boot/grub2/grub.cfg >/dev/null 2>&1; then
    grub_config_ok=true
fi

# 检查user.cfg文件
uefi_config_ok=false
if [ -f /boot/grub2/user.cfg ]; then
    if grep -E "^GRUB2_PASSWORD=grub\.pbkdf2\.sha512" /boot/grub2/user.cfg >/dev/null 2>&1; then
        uefi_config_ok=true
    fi
fi

# 判断结果
if $grub_config_ok && $uefi_config_ok; then
    echo "[PASS] Bootloader密码已设置"
    exit 0
else
    echo "[FAIL] Bootloader密码未正确设置"
    [ ! $grub_config_ok ] && echo "错误信息：grub.cfg中缺少密码配置"
    [ ! $uefi_config_ok ] && echo "错误信息：/boot/grub2/user.cfg中缺少GRUB2_PASSWORD配置"
    exit 1
fi

